#include "world.hpp"
#include "common.h"
#include "track.hpp"
#include "train.hpp"
#include <assert.h>
#include <cmath>
#include <cstdio>


Track *World::createTrack(fp_type length, fp_type speedLimit) {
    const unsigned long currentSize = this->tracks.size();
    Track *createdTrack = new Track(currentSize, length, speedLimit);
    this->tracks.push_back(createdTrack);
    return createdTrack;
}

// Train *World::createTrain() {
//     ElectricMotorProperty motorProperty = ElectricMotorProperty_createValue(
//         "YJ85-A", THREE_PHASED_ASYNC, 1250, 11852, 2662, 0.92, 4.85);
//     ElectricMotor *motors = ElectricMotor_createMulti(6);

//     ElectricLocomotive *loco =
//         Locomotive_create_electric(10, 23, 23.0 * 6, 1.25, 6, motorProperty);
//     printf("motor maxpower %lf\n", motorProperty.maxPower);
//     printf("motor maxpower %lf\n", loco->motorProperty.maxPower);
//     assert(FLOAT_CLOSE(loco->base.startSpeed, 10.0));
//     assert(loco->base.maxPower > 1000.0);
//     ASSERT_FLOAT_CLOSE(loco->motorProperty.gearRatio, 4.85);
//     ASSERT_FLOAT_CLOSE(loco->motorProperty.maxRPM, 2662.0);

//     const int WAGON_NUM = 2;
//     RailroadCarProperty *property = RailroadCarProperty_create(
//         "N6", RAILROAD_CAR_TYPE_FLATCAR, 12.5, 100, 21.5, 60);
//     RailroadWagon **wagons = static_cast<RailroadWagon **>(
//         malloc(sizeof(RailroadWagon *) * WAGON_NUM));
//     for (int i = 0; i < 2; i++) {
//         wagons[i] = RailroadWagon_create(property);
//     }

//     Train *train = Train_create(((Locomotive **)&loco), 1, wagons,
//     WAGON_NUM);

//     // this->trainsOnTrack.push_back(train);
//     this->allTrains.push_back(train);
//     return train;
// }

// void World::assignRoute(Train *train, std::vector<Track *> tracks,
//                         std::vector<DIRECTION> directions) {
//     const int length = tracks.size();
//     // tracks
//     Route *route = Route_create(&tracks[0], &directions[0], length);
//     Train_setRoute(train, route);
//     return;
// }